package com.example.spark.rdd;

import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;

import java.util.Arrays;
import java.util.List;

public class SparkRDDExample_1 {
    public static void main(String[] args) {

        //创建配置对象
        SparkConf conf = new SparkConf();
        conf.setMaster("local[*]");
        conf.setAppName("spark_demo");

        //创建SparkContext
        JavaSparkContext jsc = new JavaSparkContext(conf);
        //编写逻辑代码

        List<String> list = Arrays.asList("hello", "spark");
        JavaRDD<String> rdd = jsc.parallelize(list);

        List<String> result = rdd.collect();
        //遍历返回结果的集合并打印
        result.forEach(System.out::println);

        //关闭,回收资源
        jsc.stop();


    }



}
